package com.link2room.rodimus.controller.manager;

import com.link2room.common.dto.result.base.BaseResultDto;
import com.link2room.rodimus.facade.IMallManagerFacadeService;
import com.link2room.sideswipe.permissionResouces.annotation.L2RPermissionResources;
import com.link2room.rodimus.dto.param.manager.MallGoodCategoryCreateParamDto;
import com.link2room.rodimus.dto.param.manager.MallGoodCategoryDeleteParamDto;
import com.link2room.rodimus.dto.param.manager.MallGoodCategoryFindParamDto;
import com.link2room.rodimus.dto.param.manager.MallGoodCategoryUpdateParamDto;
import com.link2room.rodimus.dto.result.base.MallGoodCategoryDto;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

import static com.link2room.rodimus.constant.PermissionConstant.createMallGoodCategory;

/**
 * Created by LN on 2017/11/22
 */
@Api(tags = "商城商品类目")
@RestController
@RequestMapping("/manager/MallGoodCategories")
public class MalGoodCategoryManagerController {
    @Resource
    private IMallManagerFacadeService mallManagerFacadeService;

    @ApiOperation(value = "商品类目列表", response = MallGoodCategoryDto.class)
    @ApiImplicitParams(value = {
            @ApiImplicitParam(name = "isHalt", value = "是否禁用", paramType = "query", required = false),
    })
    @RequestMapping(method = RequestMethod.GET)
    public BaseResultDto getMallGoodCategories(
            @RequestParam(name="isHalt",required = false)String isHalt
    ) throws Exception {
        MallGoodCategoryFindParamDto paramDto = new MallGoodCategoryFindParamDto();
        paramDto.setIsHalt(isHalt);
        BaseResultDto res = new BaseResultDto();
        res.setResultCode(0);
        res.setQueryResult(mallManagerFacadeService.getGoodCategorise(paramDto));
        return res;
    }

    @RequestMapping(method = RequestMethod.POST)
    @ApiOperation(value = "新建商品类目")
    @L2RPermissionResources(value = createMallGoodCategory, name = "新建商品类目")
    public BaseResultDto createMallGoodCategory(
            @RequestBody MallGoodCategoryCreateParamDto paramDto
    ) throws Exception {
        mallManagerFacadeService.createGoodCategories(paramDto);
        BaseResultDto res = new BaseResultDto();
        res.setResultCode(0);
        return res;
    }

    @RequestMapping(value = "/{mallGoodCategoryCode}",method = RequestMethod.GET)
    @ApiOperation(value = "新建商品类目")
    @ApiImplicitParams(value = {
            @ApiImplicitParam(name = "mallGoodCategoryCode", value = "商品类目代码", paramType = "path", required = true),
     }
    )
    public BaseResultDto createMallGoodCategory(
            @PathVariable("mallGoodCategoryCode") String mallGoodCategoryCode
    ) throws Exception {
        MallGoodCategoryFindParamDto paramDto = new MallGoodCategoryFindParamDto();
        paramDto.setGoodCategoryCode(mallGoodCategoryCode);
        BaseResultDto res = new BaseResultDto();
        res.setResultCode(0);
        res.setResultInfo(mallManagerFacadeService.getMallGoodCategory(paramDto));
        return res;
    }

    @RequestMapping(value = "/{mallGoodCategoryCode}",method = RequestMethod.PUT)
    @ApiOperation(value = "更新商品类目")
    @ApiImplicitParams(value = {
            @ApiImplicitParam(name = "mallGoodCategoryCode", value = "商品类目代码", paramType = "path", required = true),
    }
    )
    public BaseResultDto updateMallGoodCategory(
            @RequestBody MallGoodCategoryUpdateParamDto paramDto,
            @PathVariable("mallGoodCategoryCode") String mallGoodCategoryCode) throws Exception {
        paramDto.setGoodCategoryCode(mallGoodCategoryCode);
        mallManagerFacadeService.updateMallGoodCategory(paramDto);
        BaseResultDto res = new BaseResultDto();
        res.setResultCode(0);
        return res;
    }
    @RequestMapping(value = "/{mallGoodCategoryCode}",method = RequestMethod.DELETE)
    @ApiOperation(value = "删除商品类目")
    public BaseResultDto deleteMallGoodCategory(

            @PathVariable("mallGoodCategoryCode") String mallGoodCategoryCode) throws Exception {
        MallGoodCategoryDeleteParamDto paramDto = new MallGoodCategoryDeleteParamDto();

        paramDto.setGoodCategoryCode(mallGoodCategoryCode);
        mallManagerFacadeService.deleteMallGoodCategory(paramDto);
        BaseResultDto res = new BaseResultDto();
        res.setResultCode(0);
        return res;
    }




}
